package com.example.hotel_lxy.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.hotel_lxy.R;
import com.example.hotel_lxy.base.TypePay;
import com.example.hotel_lxy.bean.ScheduledBean;
import com.example.hotel_lxy.net.Api;
import com.example.hotel_lxy.utils.SPUtils;
import com.ysxsoft.common_base.base.RBaseAdapter;
import com.ysxsoft.common_base.base.RViewHolder;
import com.ysxsoft.common_base.utils.DisplayUtils;
import com.ysxsoft.common_base.utils.JsonUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.List;

import okhttp3.Call;

//宴会厅
public class DataReserveAddViewDialog extends Dialog {
    private Context mContext;
    RecyclerView rv_Data_selection;
    private static List<TypePay> SpTypeList;
    public DataReserveAddViewDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = context;
    }

    private View init() {
        View view = View.inflate(mContext, R.layout.dialog_dataselection, null);
        rv_Data_selection=view.findViewById(R.id.rv_Data_selection);
        showData();
        return view;
    }

    private void showData() {
        rv_Data_selection.setLayoutManager(new LinearLayoutManager(mContext));
        RBaseAdapter<TypePay> rBaseAdapterAllType = new RBaseAdapter<TypePay>(
                mContext, R.layout.item_item_popwindow, SpTypeList) {
            @Override
            protected void fillItem(RViewHolder holder, TypePay item, int position) {
                TextView text_title = holder.itemView.findViewById(R.id.text_title);
                text_title.setText(item.getName());
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        listener.onPositiveClick(item.getId()+"",item.getName());
                        dismiss();
                    }
                });
            }

            @Override
            protected int getViewType(TypePay item, int position) {
                return 0;
            }
        };
        rv_Data_selection.setAdapter(rBaseAdapterAllType);

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCanceledOnTouchOutside(true);
//        setCancelable(false);
        setContentView(init());
    }

    public void showDialog() {
        if (!isShowing()) {
            show();
            WindowManager.LayoutParams lp = getWindow().getAttributes();
//            lp.height = DisplayUtils.getDisplayWidth(mContext) * 5 / 5;
            lp.width = DisplayUtils.getDisplayWidth(mContext) * 8 / 10;
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
            getWindow().setAttributes(lp);
            getWindow().setGravity(Gravity.CENTER);
        }
    }

    public static DataReserveAddViewDialog show(Context context, OnDialogClickListener listener, List<TypePay> SpTypeLists) {
        DataReserveAddViewDialog dialog = new DataReserveAddViewDialog(context, R.style.BottomDialogStyle);
        dialog.setListener(listener);
        SpTypeList=SpTypeLists;
        dialog.showDialog();
        return dialog;
    }

    public OnDialogClickListener listener;

    public DataReserveAddViewDialog setListener(OnDialogClickListener listener) {
        this.listener = listener;
        return this;
    }

    public interface OnDialogClickListener {
        /**
         * 点击确定按钮事件
         */
        public void onPositiveClick(String id, String name);
    }
}
